<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        function createPerson(name, age, gender) {

            //使用this来引用新建的对象
            this.name = name;
            this.age = age;
            this.gender = gender;
            this.sayName = function () {
                alert(this.name)
            }
        }


        //使用new关键字调用的函数是构造函数（类）
        var per = new createPerson("猪八戒", 25, "男");
        var per2 = new createPerson("蜘蛛精", 15, "女");
        var per3 = new createPerson("白骨精", 35, "女");

        console.log(per);
        per.sayName();

        console.log(per2);
        per2.sayName();

        console.log(per3);
        per3.sayName();


        //使用instanceof来检查一个对象是否是一个类的实例
        console.log(per instanceof createPerson);

    </script>

<body>
</body>

</html>